<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>版本信息编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/web/res/css/xadmin.css">
    <script src="/web/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/web/res/js/xadmin.js"></script>
    <script type="text/javascript" src="/web/res/kindeditor4110/kindeditor-min.js" charset="utf-8"></script>
</head>

<body style="background-color: white;">
<div class="layui-fluid" id="orderEdit">
    <form class="layui-form layui-form-pane" id="formsubmit" action="/after/privilege/guiZuSave">
        <input type="hidden" id="id" name="id" value="${(byId.id?c)!''}">

        <div class="layui-form-item">
            <label class="layui-form-label"  style="width: 200px;">贵族名称</label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" value="${byId.name!''}" required lay-verify="required"
                       autocomplete="off" class="layui-input"/>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">购买金额(钻石)</label>
            <div class="layui-input-inline">
                <input type="number" id="money" name="money" value="${(byId.money?c)!''}" required lay-verify="required"
                       autocomplete="off" class="layui-input"/>
            </div>
        </div>

        <!-- <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">赠送的免费时长(分钟)</label>
            <div class="layui-input-inline">
                <input type="number" id="freetime" name="freetime" value="${(byId.freetime?c)!''}" required lay-verify="required"
                       autocomplete="off" class="layui-input"/>
            </div>
        </div> -->


        <div class="layui-form-item">
            <label class="layui-form-label"  style="width: 200px;">勋章</label>
            <div class="layui-upload">
                <div class="upload-imgBox" style="width: auto;height: auto">
                    <img class="upload-select-img" name="medal" id="medal" src="${byId.medal!''}"
                         style="width: 200px;height:auto;float: left;">
                </div>
                <button type="button" name="photo" id="photo" class="layui-btn test1" style="margin-left: 20px;">上传图片
                </button>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"  style="width: 200px;">头像框</label>
            <div class="layui-upload">
                <div class="upload-imgBox" style="width: auto;height: auto">
                    <img name="frame" id="frame" src="${byId.frame!''}" style="width: 200px">
                </div>
                <button type="button" name="photo" id="photo" class="layui-btn test2" style="margin-left: 20px;">上传图片
                </button>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label"   style="width: 200px;">贵族宣传图</label>
            <div class="layui-upload">
                <div class="upload-imgBox" style="width: auto;height: auto">
                    <img name="xuanchuan" id="xuanchuan" src="${byId.xuanchuan!''}" style="width: 200px">
                </div>
                <button type="button" name="photo" id="photo" class="layui-btn test3" style="margin-left: 20px;">上传图片</button>
            </div>
        </div>

     <#--   <div class="layui-form-item">
            <label class="layui-form-label"  style="width: 200px;">内容</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" id="neirong" name="neirong"
                          style="height:350px;width: 658px">${(byId.neirong)!''}</textarea>
            </div>
        </div>-->

        <div class="layui-form-item" >
            <label class="layui-form-label" style="width: 200px;">是否拥有专属坐骑</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="iszuoqi1" value="1" lay-skin="switch" lay-filter="switchZuoqi"  lay-text="是|否"
                       <#if byId.iszuoqi?exists && (byId.iszuoqi)?number == 1>checked </#if>/>
            </div>
        </div>

        <div class="layui-form-item" id="zuoqu123" <#if byId.iszuoqi?exists && (byId.iszuoqi)?number == 2>style="display: none"</#if>>
            <label class="layui-form-label">专属坐骑</label>
            <div class="layui-input-inline">
                <select name="zuoqiid" id="zuoqiid" lay-filter="typeone" lay-verify="required"
                        style="margin: 0;">
                    <#list zuoqiList as ts>
                        <option value="${(ts.id?c)!''}" <#if byId?exists && byId.zuoqiid?exists><#if (byId.zuoqiid)?number == ts.id?number>selected</#if></#if>>${ts.name!''}</option>
                    </#list>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 200px;">是否拥有专属头饰</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="istoushi1" value="1" lay-skin="switch" lay-filter="switchToushi"  lay-text="是|否"
                       <#if byId.istoushi?exists && (byId.istoushi)?number == 1>checked </#if>/>
            </div>
        </div>

        <div class="layui-form-item" id="toushi123" <#if byId.istoushi?exists && (byId.istoushi)?number == 2>style="display: none"</#if>>
            <label class="layui-form-label">专属头饰</label>
            <div class="layui-input-inline">
                <select name="toushiid" id="toushiid" lay-filter="typeone" lay-verify="required"
                        style="margin: 0;">
                    <#list toushiList as ts>
                        <option value="${(ts.id?c)!''}" <#if byId?exists && byId.toushiid?exists><#if (byId.toushiid)?number == ts.id?number>selected</#if></#if>>${ts.name!''}</option>
                    </#list>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-upload">
                <label class="layui-form-label lable-text-center">特效地址</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" id="excelname" value="${(byId.svgaAddress?html)!''}" placeholder="请上传文件"
                           autocomplete="off" class="layui-input">
                </div>
                <button type="button" class="layui-btn" id="test5"><i class="layui-icon"></i>上传文件</button>
            </div>
            <div class="layui-form-mid layui-word-aux">上传对应的特效地址，无特效不用输入</div>
        </div>

        <input id="medals" name="medals" type="hidden" value="${byId.medal!''}">
        <input id="frames" name="frames" type="hidden" value="${byId.frame!''}">
        <input id="roomnoblepics" name="roomnoblepics" type="hidden" value="${byId.xuanchuan!''}">

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit lay-filter="save">&emsp;确认&emsp;
                </button>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" onclick="xadmin.close()">
                    &emsp;返回&emsp;
                </button>
            </div>
        </div>

        <input id="iszuoqi" name="iszuoqi" type="hidden" value="${(byId.iszuoqi?c)!''}">
        <input id="istoushi" name="istoushi" type="hidden" value="${(byId.istoushi?c)!''}">

    </form>
</div>

<script>
    KindEditor.ready(function (K) {
        var editor1 = K.create('textarea[id="neirong"]', {
            cssPath: '/web/res/kindeditor4110/plugins/code/prettify.css',
            uploadJson: '/btpeizhi/fileUploadpeizhi',
            fieldName: 'imgFile',
            allowImageRemote: false,
            items: ['source', '|', 'justifyleft', '|', 'justifycenter', '|', 'justifyright', '|', 'justifyfull', '|', 'fontname', '|', 'fontsize', '|', 'forecolor', '|', 'hilitecolor', '|', 'bold', '|', 'italic', '|', 'underline', '|', 'strikethrough', '|', 'removeformat', '|', 'image'],
            afterBlur: function () {
                this.sync();
            }//******这一步非常重要，如果遗漏，则后台无法接收到数据。
        });
        prettyPrint();
    });
</script>


<script>
    layui.use(['form', 'upload'], function () {
        let $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        //$('.upload-imgBox').hide();
        form.render();

        upload.render({
            elem: '.test1',
            url: '/after/gift/uploadLiveImg',
            before: function (obj) {
                console.log(obj);
                $('.upload-img').hide();
                $('.upload-imgBox').show();
                layer.load();
                obj.preview(function (index, file, result) {
                    $('#medal').attr('src', result);
                });
            }, done: function (res) {
                $("#medals").val(res.data.name);
                layer.closeAll('loading');
                layer.msg('上传成功');
            }
        });
        upload.render({
            elem: '.test2',
            url: '/after/gift/uploadLiveImg',
            before: function (obj) {
                $('.upload-img').hide();
                $('.upload-imgBox').show();
                layer.load();
                obj.preview(function (index, file, result) {
                    $('#frame').attr('src', result);
                });
            }, done: function (res) {
                layer.closeAll('loading');
                $("#frames").val(res.data.name);
                layer.msg('上传成功');
            }
        });

        upload.render({
            elem: '.test3',
            url: '/after/gift/uploadLiveImg',
            before: function (obj) {
                $('.upload-img').hide();
                $('.upload-imgBox').show();
                layer.load();
                obj.preview(function (index, file, result) {
                    $('#xuanchuan').attr('src', result);
                });
            }, done: function (res) {
                $("#roomnoblepics").val(res.data.name);
                layer.closeAll('loading');
                layer.msg('上传成功');
            }
        });
        $.fn.extend({
            serializeObject: function () {
                var obj = {}; //声明一个对象
                $.each(this.serializeArray(), function (index, field) {
                    obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
                })
                return obj;
            }
        });


        $(function () {
            $('#saudiw img').on('click', function () {
                layer.photos({
                    photos: '#saudiw',
                    shadeClose: false,
                    closeBtn: 2,
                    anim: 0
                });
            })
        });


        //监听单选框
        //监听指定开关
        form.on('switch(switchZuoqi)', function(data){
            if(this.checked){
                $("#zuoqu123").css("display","block");
                $("#iszuoqi").val(1);
            }else{
                $("#zuoqu123").css("display","none");
                $("#iszuoqi").val(2);
            }

        });
        form.on('switch(switchToushi)', function(data){
            if(this.checked){
                $("#toushi123").css("display","block");
                $("#istoushi").val(1);
            }else{
                $("#toushi123").css("display","none");
                $("#istoushi").val(2);
            }

        });

        upload.render({
            elem: '#test5'
            , url: '/after/gift/uploadLiveImg'
            , accept: 'file'
            , choose: function (obj) {
                obj.preview(function (index, file, result) {
                    $('#excelname').val(file.name);

                });
            }
            , before: function (obj) {
                layer.load();
            }
            , done: function (res) {
                layer.closeAll('loading');
                $('#excelname').val(res.data.name);
                $("#gifteffectss").val(res.data.imgname);
                layer.msg('上传成功');
                console.log("-----" + $("#gifteffectss").val());
            }
        });


        form.on('submit(' + $("button[lay-submit]:eq(0)").attr("lay-filter") + ')', function (data) {
            if(parseInt($("#iszuoqi").val())===1){
                console.log($("#zuoqiid").val())
                if($("#zuoqiid").val()=='' || $("#zuoqiid").val()==null) {
                    layer.msg("请选择专属坐骑", {icon: 2, time: 3000}, function () {
                    });
                    return false;
                }
            }
            if(parseInt($("#istoushi").val())===1){
                if($("#toushiid").val()=='' || $("#toushiid").val()==null) {
                    layer.msg("请选择专属头饰", {icon: 2, time: 3000}, function () {
                    });
                    return false;
                }
            }
            $("input[id='excelname']").each(function (index, ele) {
                $(this).attr("name", "svgaAddress");
            });
            layer.confirm('确认要保存吗？', function (index) {

                ajaxPost($, $("#formsubmit").attr("action"), $("#formsubmit").serializeObject(), function (data) {
                    if (data.code === 0) {
                        layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                            xadmin.father_reload();
                        });
                    } else {
                        layer.close(loading);
                        layer.msg(data.msg, {icon: 2, time: 3000}, function () {

                        });
                    }
                });
            });
        });
        form.on('select(vipZu)', function (data) {
            //对应lay-filter
            $("#vipZuValue").val(data.value);

            //获取value值
        });
    });


    var E = window.wangEditor;
    var editor5 = new E('#editor5');
    editor5.create();
    editor5.txt.html('${byId.neirong}');

</script>
</body>

</html>